<?php

require("model/Plan.php");

class class_Plan {
	var $plan;
	function __construct() {
		$this->plan = new Plan();
	}

	public function method_getPlanes($params, $error) {
		try{
			$filter = $params[0]->criteria;
			$planes = $this->plan->getAll($filter);
			return $planes;
		}catch(Exception $x){
			$error->SetError(JsonRpcError_Unknown, "Error al obtener los planes");
			return $error;
		}
	}

	public function method_getPlan($params, $error){
		try{
			$idPlan = $params[0];
			$plan = $this->plan->getOwn($idPlan, null);
			return $plan;
		}catch(Exception $x){
			$error->SetError(JsonRpcError_Unknown, "Error al obtener un plan");
			return $error;
		}
	}

	public function method_insertPlan($params, $error){
		try{
			$plan = $params[0];
			return $this->plan->insert($plan);
		}catch(Exception $x){
			$error->SetError(JsonRpcError_Unknown, "Error al insertar el plan");
			return $error;
		}
	}

	public function method_deletePlan($params,$error){
		try{
			$idPlan = $params[0];
			return $this->plan->delete($idPlan);
		}catch(Exception $x){
			$error->SetError(JsonRpcError_Unknown, "Error al eliminar el plan");
			return $error;
		}
	}

	public function method_editPlan($params,$error){
		try{
			$plan = $params[0];
			return $this->plan->edit($plan);
		} catch(Exception $x){
			$error->SetError(JsonRpcError_Unknown, "Error al editar el plan");
			return $error;
		}
	}
}

?>